package 伴生对象

object ApplyDemo {
  def main(args: Array[String]): Unit = {

    val dog = new Dog("旺财")
    val dog1 = Dog("小黄")
    val dog2 = Dog()
    println(dog.name)
    println(dog1.name)
    println(dog2.name)

  }

}

class Dog(pName: String) {
  val name: String = pName
}

object Dog {
  def apply(pName: String): Dog = new Dog(pName)

  def apply(): Dog = new Dog("匿名")

}
